package org.myorg.v5;

import java.io.*;

/*
 * This class is calculate the result of resource allocation
 * 2011-10-19
 */

public class Result {

	public static void main(String[] arg) {
		System.out.println("enter main");
		
		String str[] = new String[8];
		
/*		String str[1] = "2310252554";
		String str[2] = "1453230141";
		String str3 = "2312002054";		
		String str4 = "5312022054";
		
		String str5 = "1320352225";
		String str6 = "0123450123";		
		String str7 = "3451132021";*/
		
		str[0] = "2310252554";
		str[1] = "1453230141";
		str[2] = "2312002054";		
		str[3] = "5312022054";
		
		str[4] = "1320352225";
		str[5] = "0123450123";		
		str[6] = "3451132021";
		
		Fmap fc = new Fmap();
		FPeople5 myp = new FPeople5(7, fc.getM(), fc.getGoals_num(),fc.getN());
		
		for (int i =0; i < myp.p_num; i++) {
			myp.getPersons()[i].setGene(str[i]);
		}
		
		System.out.println("will write files");
		try {
			String filePath = "./solution3";

			File myFilePath = new File(filePath);
			if (!myFilePath.exists()) {
				myFilePath.createNewFile();
			}
			FileWriter resultFile = new FileWriter(myFilePath);
			PrintWriter myFile = new PrintWriter(resultFile);
			String res[] = new String[fc.get_goals_num()];
			for (int i = 0; i < res.length; i++) {
				res[i] = "";
			}
			
			String ratio[] = new String[fc.get_goals_num()];
			for (int i = 0; i < ratio.length; i++) {
				ratio[i] = "";
			}

			String rec = "";
			for (int i = 0; i < myp.p_num; i++) {
				
				rec = rec + "\n" + myp.persons[i].gene + "\n";

				
					for(int j = 0; j < fc.get_goals_num(); j++) {
						//g[j] = g[j] + my_p.persons[i].goals[j] + " ";	
						double[][] temp = fc.cal_resource(myp.personAt(i), j);
						String str1 = "";
						String str2 = "";
						for (int k = 0; k < fc.getN(); k++) {
							//res[j] = res[j] + temp[k][0] + " ";
							//ratio[j] = ratio[j] + temp[k][1] + " ";
							
							str1 = str1 + temp[k][0] + "\t";
							str2 = str2 + temp[k][1] + "\t";

						}
						str1 = str1 + temp[fc.getN()][0] + "\t";
						str2 = str2 + temp[fc.getN()][1] + "\t";
						rec = rec + str1 + "\n" + str2 + "\n";
					}



			}

		
		
			
			System.out.println(rec);

			myFile.println(rec);

			myFile.close();
			resultFile.close();
		}
		catch (Exception e) {
			//message = "创建文件操作出错";
		}
		
		


		System.out.println("leave main");
		
		
	}
}
